<template>
  <div class="container">
    <el-card shadow="hover" class="card">
      <el-form label-width="100px" class="demo-dynamic">
        <el-divider content-position="left">apk & wgt上传</el-divider>
        <el-col :span="12" :offset="4">
          <el-form-item label="apk上传：">
            <el-upload
              action="fakeIp"
              :file-list="apkList"
              name="file"
              :http-request="uploadApk"
            >
              <el-button slot="trigger" size="small" type="primary">
                选取Apk
              </el-button>
            </el-upload>
          </el-form-item>
        </el-col>
        <el-col :span="12" :offset="4">
          <el-form-item label="wgt上传：">
            <el-upload
              action="fakeIp"
              :file-list="gwtList"
              name="file"
              :http-request="uploadGwt"
              :on-success="uploadSuccess"
            >
              <el-button slot="trigger" size="small" type="primary">
                选取wgt
              </el-button>
            </el-upload>
          </el-form-item>
        </el-col>
        <el-col :span="12" :offset="4">
          <el-form-item label="apk地址:">
            <el-tag>
              http://aixinfang-app-1.oss-cn-beijing.aliyuncs.com/app_android.apk
            </el-tag>
          </el-form-item>
          <el-form-item label="wgt地址:">
            <el-tag>
              http://aixinfang-app-1.oss-cn-beijing.aliyuncs.com/app_android.wgt
            </el-tag>
          </el-form-item>
        </el-col>
      </el-form>
    </el-card>
  </div>
</template>
<script>
  import { uploadPkg, downloadPkg } from '@/api/app'
  export default {
    name: 'App',
    data() {
      return {
        fakeIp: 'default',
        downloadLinkAddress: '',
        apkVersion: '',
        gwtVersion: '',
        apkList: [],
        gwtList: [],
      }
    },
    mounted() {},
    methods: {
      uploadSuccess() {
        console.log()
      },
      async showLinkTip(type) {
        const { data } = await downloadPkg(type)
        if (data.status === 0) {
          this.downloadLinkAddress = data.body
        } else {
          this.downloadLinkAddress = data.message
          this.$baseMessage(data.message, 'error')
        }
      },
      // formData.append('packageType', 'apk')
      async uploadApk(param) {
        console.log(param)
        const formData = new FormData()
        formData.append('packageType', 'apk')
        formData.append('file', param.file)
        const loading = this.$loading({
          lock: true,
          text: '上传中...',
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)',
        })
        const { data } = await uploadPkg(formData)
        if (data.status == 0) {
          loading.text = '上传成功！'
          // this.$baseMessage(data.message, 'success')
          loading.close()
        } else {
          // this.$baseMessage(data.message, 'error')
          loading.text = '上传失败！'
          loading.close()
        }
      },
      async uploadGwt(param) {
        console.log(param)
        const formData = new FormData()
        formData.append('packageType', 'wgt')
        formData.append('file', param.file)
        console.log(formData)
        const loading = this.$loading({
          lock: true,
          text: '上传中...',
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)',
        })
        const { data } = await uploadPkg(formData)
        if (data.status == 0) {
          loading.text = '上传成功！'
          // this.$baseMessage(data.message, 'success')
          loading.close()
        } else {
          // this.$baseMessage(data.message, 'error')
          loading.text = '上传失败！'
          loading.close()
        }
      },
    },
  }
</script>
<style lang="scss" scoped>
  .container {
    display: flex;
    flex-direction: column;
  }
  .row-bg {
    padding: 10px 0;
    background-color: #f9fafc;
  }
  .card {
    border-radius: 20px;
    transition: all 0.3s cubic-bezier(0, 0, 0.5, 1);
  }
</style>
